//
//  TBRModuleCell.m
//  TBRentClient
//
//  Created by tonbright on 2018/4/23.
//  Copyright © 2018年 tonbright. All rights reserved.
//
//图片间隙
#define kPictureMargin 10
//屏幕的尺寸
#define kMainScreenSize [UIScreen mainScreen].bounds.size
#import "TBRModuleCell.h"
@interface TBRModuleCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionView_H;
@property (nonatomic,assign)CGFloat pictureW;

@end
@implementation TBRModuleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    CGFloat pictureW = (kMainScreenSize.width - kPictureMargin * 3) / 2;
    _pictureW = pictureW;
    //设置layout
    _flowLayout.itemSize = CGSizeMake(pictureW, 97);
    _flowLayout.minimumLineSpacing = 0;
    _flowLayout.minimumInteritemSpacing = 0;
    _flowLayout.sectionInset = UIEdgeInsetsMake(kPictureMargin, kPictureMargin, kPictureMargin, kPictureMargin);
    
    _collectionView_H.constant = ((4 - 1) / 2 + 1) * 97 + 30;

    //注册nib
    [self.collectionView registerNib:[UINib nibWithNibName:@"TBREnumModuleCell" bundle:nil] forCellWithReuseIdentifier:@"TBREnumModuleCellId"];
}

- (void)setModuleArray:(NSMutableArray *)moduleArray {
    _moduleArray = moduleArray;
    NSInteger count = moduleArray.count;
    _collectionView_H.constant = ((count - 1) / 2 + 1) * 97;
    [self.collectionView reloadData];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
    return self.moduleArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TBREnumModuleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TBREnumModuleCellId" forIndexPath:indexPath];
//    KCModuleModel *enumModuleModel = self.moduleArray[indexPath.item];
//    enumModuleModel.DownloadiOS = [HelpObject changeNull:enumModuleModel.DownloadiOS];
//    cell.enumModuleModel = enumModuleModel;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(enumModuleCellClick:)]) {
        [self.delegate enumModuleCellClick:indexPath.row];
    }
}

@end
